﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RN.ERP.BLL.Material;
using RN.ERP.DTO;

namespace RN.ERP.Web.Demo
{
    public partial class Demo3Treeview : System.Web.UI.Page
    {
        static List<MateClass> listMC = new List<MateClass>();
        static List<MateClass> listtmpMC = new List<MateClass>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MaterialClassBLL objMCBLL = new MaterialClassBLL();
                listMC = objMCBLL.GetList();
                BindTree("000");
            }
        }


        private void BindTree(string pid)
        {
            foreach (MateClass item in listMC.Where(t => t.cPMCCode == pid).ToList())
            {
                TreeNode node = new TreeNode();
                node.Text = item.cMCName.ToString();
                node.Value = item.cMCCode.ToString();
                this.TreeView1.Nodes.Add(node);
                BindNode(node);
            }
        }
        private void BindNode(TreeNode nd)
        {
            foreach (MateClass item in listMC.Where(t => t.cPMCCode == nd.Value).ToList())
            {
                TreeNode node = new TreeNode();
                node.Text = item.cMCName.ToString();
                node.Value = item.cMCCode.ToString();

                nd.ChildNodes.Add(node);

                BindNode(node);
            }

        }

        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            //this.TreeView1.SelectedNode.Value
        }
    }
}